<template>
	<view>
		<view class="orderBox">
			<view class="orderItem">
				公司名称：{{orderDetail.company}}
			</view>
			<view class="orderItem">
				地址：{{orderDetail.address}}
			</view>
			<view class="orderItem">
				部门：{{orderDetail.department}}
			</view>
			<view class="orderItem">
				报修人：{{orderDetail.linkman}}
			</view>
			<view class="orderItem">
				联系方式：{{orderDetail.phoneNumber}}
			</view>
			<view class="orderItem">
				报修服务：{{orderDetail.typeList[0]}}
			</view>
			<view class="orderItem">
				报修备注：{{orderDetail.detail}}
			</view>
			<view class="orderItem">
				报修图片：
			</view>
			<!-- 图片区域 -->
			<view class="imgBox" v-if="imgItem!=''">
				<view class="imgList" v-for="(val,key) in imgItem" :key="key">
					<image class="" :src="'https://zioncloud.top/repair'+val" @click="imgPreview(key,imgItem)"></image>
				</view>
			</view>
			<!-- <button v-if="orderStatus==5" type="default" @click="goToEvaluate">前往评价</button> -->
			<view class="submitBtn">
				<u-button :disabled="evaluateId" v-if="orderStatus==4" type="default" @click="goToEvaluate">{{evaluateInfo}}</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderId: '',
				openId: '',
				orderDetail: [],
				imgItem: [],
				//订单状态
				orderStatus:'',
				recordId:0,
				// 判断是否已经评价了
				evaluateId:false,
				evaluateInfo:'前往评价'
			}
		},
		onShow() {
			if(this.recordId>=1){
				this.evaluateId=uni.getStorageSync('evaluateId');
				console.log('内测试')
				if(this.evaluateId){
					this.evaluateInfo='您已评价';
					console.log('您已评价');
				}
			}
			this.recordId=1+this.recordId;
			console.log('测试一')
		},
		methods: {
			//前往评价页面
			goToEvaluate(){
				let that = this;
				uni.navigateTo({
					url:'../evaluate/evaluate?orderId='+that.orderId
				})
			},
			//预览图片
			imgPreview(key, imgItem) {
				let arrList = [];
				let img = 'https://zioncloud.top/repair';
				// 写入完整的图片路径
				imgItem.forEach(function(value, index) {
					arrList[index] = img + value;
					console.log(arrList);
				})
				uni.previewImage({
					current: key,
					urls: arrList
				})
			},
			//获取订单详细信息
			getOrderDetail() {
				let that = this;
				uni.request({
					url: "https://zioncloud.top/repair/order/getOrder",
					headers: {
						'Content-Type': 'application/json'
					},
					data: {
						"orderId": that.orderId,
						"openId": that.openId,
					},
					method: "POST",
					success(res) {
						that.orderDetail = res.data.data.order;
						that.imgItem = that.orderDetail.imgList;
						console.log(that.orderDetail);
						that.orderStatus=res.data.data.order.status;
						console.log(that.orderStatus);
					}
				})
			}
		},
		onLoad(option) {
			this.orderId = option.orderId;
			this.openId = uni.getStorageSync('openId');
			//获取订单详细信息
			this.getOrderDetail();
		}
	}
</script>

<style>
	.orderItem {
		height: 65rpx;
		line-height: 65rpx;
		/* width: 100%; */
		margin-left: 40rpx;
		margin-right: 25rpx;
		border-bottom: 1rpx solid #eee;
	}

	/* 图片预览 */
	.imgList {
		width: 18%;
		height: 120rpx;
		margin: 6rpx;
		float: left;
		/* position:relative; */
	}

	.imgList image {
		width: 100%;
		height: 100%;
	}

	.imgBox {
		margin-left: 40rpx;
		margin-right: 25rpx;
		border: #007AFF solid 1rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}
	.submitBtn{
		width:50%;
		position:absolute;
		left:50%;
		transform: translate(-50%,0);
		bottom: 15%;
	}
</style>
